unit dSequencia;

interface
 uses
  Classes,
  SysUtils,
  dConexao;

  function GeraSequencia(ATabela : string; ACampo : string) : Integer;

implementation

function GeraSequencia(ATabela : string; ACampo : string) : Integer;
const
 ASql = 'select max(%s) contador from %s ';
var
 fQry : TdQuery;
 FSql : string;
begin
 try
  fQry := TdQuery.Create(nil,'R');
  FSql := format(ASql,[ACampo,ATabela]);
  fQry.Open(FSql);
  result := fQry.fieldbyname('contador').AsInteger+1;
 finally
  FreeAndNil(fQry);
 end;

end;

end.
